Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ambiguity expansion iterator #46

Merged
merged 4 commits into from
Oct 17, 2023
Merged

Add ambiguity expansion iterator #46

merged 4 commits into from
Oct 17, 2023

Conversation

swooster
Copy link
Contributor

Intent

If we're going to support wobble-codes we'll need some kind of support for expansions. Instead of using the pipeline's expansion code, this uses an iterator-based approach because that allows calculating the number of expansions without actually enumerating each one, so the API doesn't need an expansion cap to be specified upfront. Additionally, the included benchmarks show that switching to an iterator-based approach shouldn't cause any performance problems.

Changes

  • Add quickdna::expansions::{Expansion, Expansions}.
  • Add DnaSequenceAmbiguous::expansions.
  • Add expansions-related benchmarks.

@swooster swooster requested a review from a team October 17, 2023 00:02
Copy link
Contributor

@lynn lynn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid!

};

for amb in self.ambiguities.iter_mut().rev() {
amb.digit = (amb.digit + 1) % (amb.nucleotide.possibilities().len() as u8);
Copy link
Contributor

@lynn lynn Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it makes sense (and if it even makes a performance difference) to make a method on nucleotides that immediately returns the number of possibilities, rather than write .possibilities().len() (there are a few occurrences elsewhere in the PR).

Also I really like this algorithm :)

Copy link
Contributor

@lynn lynn Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking the implementation can be usize::count_ones(self.into()) because of our chosen encoding of ambiguous nucleotides, which is often a single operation (popcnt in x86).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! That's an even better idea. I'll try that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this out on my laptop with no noticeable difference, so I was about to discard that change... but just to be diligent I tried it on biofilter and it consistently yielded a whopping 15-20% performance improvement! I really need to be better about doing performance testing on biofilter instead of my dev machine.

Replaces `nuc.possibilities().len()` with `nuc.bits().count_ones()`.
@swooster swooster merged commit de251c7 into main Oct 17, 2023
8 checks passed
@swooster swooster deleted the swooster/expansions branch October 17, 2023 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants